// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import router from './router'
import axios from 'axios'
import Vuex from 'vuex'
import store from './store'


//axios加到vue的原型链
Vue.prototype.axios = axios
Vue.use(ElementUI)
Vue.use(Vuex)

Vue.config.productionTip = false

// 在跳转前执行
router.beforeEach((to, from, next) => {
  //获取用户登录状态
  let isLogin = sessionStorage.getItem("isLogin")

  if (to.path === '/logout') {
    // 清空
    sessionStorage.clear();
    // 跳转到登录
    next({path: '/login'})
  } else if (to.path === '/login') {
    if (isLogin != null) {
      next({path: '/main'})
    }
  }
  // 如果为非登录状态
  else if (isLogin == null) {
    // 跳转到登录页
    next({path: '/login'})
  }
// 下一个路由
  next();
})

/* eslint-disable no-new */
const vm = new Vue({
  el: '#app',
  router,  //路由
  store,   //vuex
  components: {App},
  template: '<App/>',
  render: h => h(App)
})

